//
//  HPBaseSwiper.h
//  HPZZTong
//
//  Created by wenjun on 14-5-7.
//  Copyright (c) 2014年 Handpay. All rights reserved.
//
//  marco modify

#import <Foundation/Foundation.h>
#import "HPSwiperResult.h"
#import "HPSwipeServiceProtocal.h"


/**
 密钥类型
 **/
typedef enum {
    EncyptTypeNone = 0,         // 原始
    EncyptTypeFastTransfer,     //快速转账（用银联密钥)
    EncyptTypeNormal,           //其他操作
}EncyptType;

typedef void (^SwiperComplete)(HPSwiperResult * swiperResult);

typedef HPSwiperResult * (^OperationBlock)(void);

#define ExecuteSwiperBlock(block,result) if(block){block(result);}

@protocol HPSwiperFunction <NSObject>
@optional

- (void)getKSN:(SwiperComplete)complete; // 获取KSN
- (void)encryptKeyData:(NSString *)keyData factor:(NSString *)factor complete:(SwiperComplete)complete; // 关键数据加密
- (void)encryptMac:(NSString *)macStr factor:(NSString *)factor complete:(SwiperComplete)complete; // mac加密
- (void)encryptPin:(NSString *)macStr factor:(NSString *)factor complete:(SwiperComplete)complete;
- (void)encyptAmount:(NSString *)amount factor:(NSString *)factor complete:(SwiperComplete)complete;
- (void)swipe:(int)time factor:(NSString *)factor complete:(SwiperComplete)complete; // 刷卡
- (void)emv:(id)emvInfo complete:(SwiperComplete)complete;
- (void)inputPwd:(int)time amount:(NSString *)amount factor:(NSString *)factor complete:(SwiperComplete)complete; // 密码输入
- (void)selectApp:(NSArray*)type time:(int)time factor:(NSString *)factor complete:(SwiperComplete)complete;
- (void)releaseInstance;
- (void)activeInstance;

@end

@interface HPBaseSwiper : NSObject <HPSwiperFunction>

@property (nonatomic) NSTimeInterval defaultTimeout;
@property (strong,nonatomic) NSString * ksn;
@property (readonly,nonatomic) SwiperState connectState;
@property (readonly,nonatomic) dispatch_queue_t swiperQueue;
@property (readonly,nonatomic) dispatch_queue_t wrapperQueue;

+ (id)sharedInstance __attribute__((deprecated));
- (id)initWithSwiperQueue:(dispatch_queue_t)swiperQueue wrapperQueue:(dispatch_queue_t)wrapperQueue;
- (void)connectStateChanged:(SwiperState)connectState; // marco make it private

//调用同步方法,OperationBlock返回nil表示异步返回结果,需要调用operationFinishedWithResult结束
- (void)doOperation:(OperationBlock)operation complete:(SwiperComplete)complete;
//调用异步方法
- (void)beginSwiperOperation:(NSInvocation *)invocation timeout:(NSTimeInterval)timeout complete:(SwiperComplete)complete;
//异步方法结束
- (void)operationFinishedWithResult:(HPSwiperResult *)swiperResult;
//停止刷卡器操作
- (void)stopSwiper;
- (BOOL)isConnected;
- (BOOL)hasOperation;

- (BOOL)isBlueThooth;
- (BOOL)canInputPin;
- (void)disconnect;
//取消当前操作
- (void)cancelSwiperOperation;
- (void)cancelSwiperOperationWithCode:(HPSwiperResultCode)resultCode;
- (void)cancelSwiper;
- (void)sleep:(NSTimeInterval)time;
- (void)stopOperation __attribute__((deprecated("instead of releaseInstance")));
- (void)startOperation __attribute__((deprecated("instead of activeInstance")));
- (BOOL)checkIsICCard:(NSDictionary*)dic;

@end